import { configureStore } from '@reduxjs/toolkit'
import useReducer,{ UserStateType } from './userReducer.ts'
import componentsReducer, { ComponentsStateType } from './componentsReducer/index.ts'
import pageInfoReducer, { PageInfoType } from './pageInfoReducer.ts'
import undoable, { excludeAction,StateWithHistory } from 'redux-undo'

export type StateType = {
    user: UserStateType
    components: StateWithHistory<ComponentsStateType> // 增加了undo
    pageInfo: PageInfoType
}
export default configureStore({
    reducer:{
        user: useReducer,
        // 分模块, 扩展: 问卷的信息
        // components: componentsReducer,
        // 组件列表(复杂 undo/redo)
        components: undoable(componentsReducer,{
            limit:20, // 限制 undo 20步
            filter: excludeAction([
                'components/resetComponents',
                'components/changeSelectedId',
                'components/selectPrevComponent',
                'components/selectNextComponent',
            ])
        }),

        // 问卷信息
        pageInfo: pageInfoReducer
    },
})

